#!/usr/bin/env python

import nltk
from nltk.corpus import brown

# ---------part A
# cfd = nltk.ConditionalFreqDist(
# 	(genre,word)
# 	for genre in brown.categories()
# 	for word in brown.words(categories=genre))
# print len(cfd)

# ---------part B
# genre_word = [
# 	(genre,word)
# 	for genre in ['news','romance']
# 	for word in brown.words(categories=genre)
# ]
# print len(genre_word)
# print genre_word[:4]
# cfd = nltk.ConditionalFreqDist(genre_word)
# print cfd.conditions();
# print cfd['news']
# print cfd['news'].most_common(20)
# print cfd['romance']['love']

# ---------part C plot
# from nltk.corpus import inaugural
# cfd = nltk.ConditionalFreqDist(
# 	(target, fileid[:4])
# 	for fileid in inaugural.fileids()
# 	for w in inaugural.words(fileid)
# 	for target in ['america','citizen']
# 	if w.lower().startswith(target)
# 	)
# cfd.plot()

# ---------part C2 plot exam
from nltk.corpus import brown
days=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
cfd = nltk.ConditionalFreqDist(
	(genre, day)
	for genre in ['news','romance']
	for day in days
	for word in brown.words(categories=genre)
	if word.lower().startswith(day.lower())
	)
cfd.tabulate()
cfd.plot()